package com.blockchain.front.servlets.api.user;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.framework.service.ServiceSession;
import com.blockchain.front.service.trading.TradingManage;
import com.blockchain.front.servlets.api.AbstractTickerServlet;
import com.blockchain.front.servlets.api.ErrorCode;
import com.blockchain.front.servlets.api.ticker.ResultMessage;
import com.blockchain.front.util.JsonUtil;
import com.blockchain.util.StringHelper;

/**
 * 机器人API接口</br>
 * 获取用户单个币种交易记录</br>
 * 修改时间：2017年7月24日16:01:35</br>
 */
@WebServlet(value = { "/api/user/getMyTradeLog" })
public class GetMyTradeLog extends AbstractTickerServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void processPost(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		ResultMessage msg = new ResultMessage();
		String market = "";
		String apikey = "";
		try {
			market = request.getParameter("market");
			apikey = request.getParameter("apikey");
		} catch (Exception e) {
			msg.error = ErrorCode.CSCU.getErrorCode();
		}

		if (!StringHelper.isEmpty(market) && !StringHelper.isEmpty(apikey)) {
			TradingManage tradingManage = serviceSession.getService(TradingManage.class);
			msg.data = tradingManage.getMyTradeLog(market, apikey);
		}
		response.getWriter().write(JsonUtil.GsonString(msg));
	}

	@Override
	protected void processGet(HttpServletRequest request, HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		processPost(request, response, serviceSession);
	}
}
